import Base from '../utils/base.js'
class NewsDetail extends Base {
  constructor() {
    super();
  }

  getDetailData(id, callBacks) {
    this.request({
      url: '/news/read/' + id,
      callback: function(res) {
        if (res.status === 1) {
          typeof callBacks === 'function' ? callBacks(res.data) : '';
        }
      }
    })
  }
  replyCount(parent_id,callBacks) {
    this.request({
      url: '/replyCount',
      data: {
        parent_id: parent_id
      },
      callback: function (res) {
        if (res.status === 1) {
          typeof callBacks === 'function' ? callBacks(res.data) : '';
        }
      }
    })
  }
  getUpvote(news_id, callBacks) {
    this.request({
      url: '/upvote/' + news_id,
      header: {
        openid: wx.getStorageSync('userInfo').openid
      },
      callback: function (res) {
        if(res.status ===1) {
          typeof callBacks === 'function' ? callBacks(res.data) : '';
        }
        

      }
    })
  }
  delUpvote(news_id, callBacks) {
    this.request({
      url: '/upvote?id=' + news_id,
      method: 'DELETE',
      header: {
        openid: wx.getStorageSync('userInfo').openid
      },
      callback: function (res) {

        typeof callBacks === 'function' ? callBacks(res) : '';

      }
    })
  }
  upvote(news_id, callBacks) {
    this.request({
      url: '/upvote',
      method: 'POST',
      header: {
        openid: wx.getStorageSync('userInfo').openid
      },
      data: {
        id: news_id
      },
      callback: function (res) {
       
          typeof callBacks === 'function' ? callBacks(res) : '';
        
      }
    })
  }
  getComments(param, page, size, callBacks) {
    this.request({
      url: '/comment',
      data: {
        page: page,
        size: size,
        id: param.news_id,
        parent_id: param.parent_id,
        comment_id: param.comment_id
      },
      callback: function(res) {
        if (res.status === 1) {
          typeof callBacks === 'function' ? callBacks(res.data) : '';
        }
      }
    })
  }

  postComment(param, callBacks) {
    this.request({
      url: '/comment',
      method: 'POST',
      header: {
        openid: wx.getStorageSync('userInfo').openid
      },
      data: {
        news_id: param.news_id,
        to_user_id: param.to_user_id,
        parent_id: param.parent_id,
        content: param.content
      },
      callback: function(res) {
        typeof callBacks === 'function' ? callBacks(res) : '';
      }
    })
  }
}
export default NewsDetail;